﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace YTSK.REF
{

    public class FrmCustomerWaitBase : Report.ReportToolBar
    {
        public Model.Customer ret;

        #region 初始化
        public FrmCustomerWaitBase(Control main, DataGridView dg, string ReportCode, ToolStrip toolstrip) :
            base(main, dg, ReportCode, toolstrip)
        { }
        #endregion

        #region  增加ToolBar的事件
        public override void InitControl()
        {
            base.InitControl();
            foreach (ToolStripItem bar in _toolstrip.Items)
            {
                if (bar.Text.Length > 0)
                { bar.Click += toolbar_click; }
            }
        }
        #endregion 增加ToolBar的事件

        #region 工具栏事件
        public override void toolbar_click(object sender, EventArgs e)
        {
            base.toolbar_click(sender, e);

            if (sender.GetType() != typeof(ToolStripButton)) { return; }
            var bt = (ToolStripButton)sender;
            var text = bt.Text;
            switch (text)
            {
                case "确定":
                    GetReturnVal();
                    _main.Parent.Hide();
                    break;
            }
        }
        #endregion

        #region 鼠标双击事件
        public void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            GetReturnVal();
            _main.Parent.Hide();
        }
        #endregion

        public void GetReturnVal()
        {
            var crow = _dg.CurrentRow;
            if (crow != null)
            {
                ret = new Model.Customer();
                ret.cCusName = crow.Cells["cCusName"].Value.ObjToString();
                ret.TaxNo = crow.Cells["TaxNo"].Value.ObjToString();
                ret.Address = crow.Cells["Address"].Value.ObjToString();
                ret.Bank = crow.Cells["Bank"].Value.ObjToString();
                ret.BankAccount = crow.Cells["BankAccount"].Value.ObjToString();
                ret.Phone = crow.Cells["Phone"].Value.ObjToString();
            }
        }
    }

}
